package com.hspedu.static_;

/**
 * @Author Stringzhua
 * @Date 2024/3/4 18:54
 * description:
 * 类变量和类方法 OOP
 */
public class ChildGame02 {
    public static void main(String[] args) {
        //定义变量count统计有多少小孩加入了游戏

//        int count = 0;

        Child02 child01 = new Child02("白骨精");
        child01.join();
//        count++;
        child01.count++;
        Child02 child02 = new Child02("狐狸精");
        child02.join();
//        count++;
        child02.count++;
        Child02 child03 = new Child02("老鼠精");
        child03.join();
//        count++;
        child03.count++;

        //游戏结束
        //类变量可以通过类名来访问
        System.out.println("共有count = " + Child02.count + "个小孩加入了游戏~");
        System.out.println("child01.count=" + child01.count);//3
        System.out.println("child02.count=" + child02.count);//3
        System.out.println("child03.count=" + child03.count);//3
    }
}

class Child02 {
    private String name;
    //定义一个变量count,是一个类变量(静态变量) static 静态
    //该变量最大的特点就是会被Child类的所有对象实例化
    public static int count = 0;

    public Child02(String name) {
        this.name = name;
    }

    public void join() {
        System.out.println(name + " 加入了游戏");
    }
}
